home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume9 / fastgrep / patch1 < prev    next >
Encoding:
Text File  |  1987-06-22  |  2.4 KB  |  72 lines

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i020: "Missing" strpbrk for 4.2BSD "fastgrep"
  5. Message-ID: <440@uunet.UU.NET>
  6. Date: 24 Jun 87 01:11:02 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 61
  9. Approved: rs@uunet.uu.net
  10.  
  11. Mod.sources: Volume 10, Number 20
  12. Submitted by: Hal Render <render@b.cs.uiuc.edu>
  13. Archive-Name: fastgrep/Patch1
  14.  
  15.  
  16. [  If you are running 4.3, SystemV, or if you have Henry's string
  17.    library posted here last volume, then you won't need this.  --r$  ]
  18.  
  19. The fastgrep sources I got were apparently incomplete.  The code in the
  20. file 'egrep.c' called for a routine 'strpbrk(s1, s2)'.  I guessed from
  21. the context that the routine looks for occurrences of characters in the
  22. second parameter string in the first parameter string, returning a pointer
  23. to the first occurrence of one of the characters.  Accordingly, I wrote a
  24. simple routine to do this.  Here it is, for the benefit of whomever wants it. 
  25. I have tested the compiled binaries, and they work fine.  Note that the
  26. Makefile included with the sources should be changed to include the file
  27. 'strpbrk.o' as one of the files assigned to the OBJ variable
  28. (i.e.  'OBJ= strpbrk.o ...' should be in the Makefile).
  29.  
  30.                                    Hal Render
  31.                                    University of Illinois at Urbana-Champaign
  32.                                    render@b.cs.uiuc.edu           (ARPA)
  33.                                    {seismo,pur-ee}!uiucdcs!render (USENET)
  34. -------------CUT HERE----------------------------------------------------------
  35. #! /bin/sh
  36. # This is a shell archive, meaning:
  37. # 1. Remove everything above the #! /bin/sh line.
  38. # 2. Save the resulting text in a file.
  39. # 3. Execute the file with /bin/sh.
  40. # The following files will be created:
  41. #    strpbrk.c
  42. # This archive created: Thu Jun 18 10:49:34 1987
  43. export PATH; PATH=/bin:$PATH
  44. if test -f 'strpbrk.c'
  45. then
  46.     echo shar: over-writing existing file "'strpbrk.c'"
  47. fi
  48. cat << \SHAR_EOF > 'strpbrk.c'
  49. #include <strings.h>
  50.  
  51. char * strpbrk(pat1, pat2)
  52.  
  53.     register char *pat1;    /* target pattern */
  54.     char *pat2;             /* list of characters to search for */
  55. {
  56.  
  57.     register char *cp1, *cp2;
  58.  
  59.     cp1 = pat2;
  60.  
  61.     while (*cp1 != '\0') {
  62.        if ((cp2 = index(pat1, *cp1)) != (char *) 0)
  63.            return(cp2); 
  64.        cp1++;
  65.     }
  66.  
  67.     return((char *) 0);
  68. }
  69. SHAR_EOF
  70. #    End of shell archive
  71. exit 0
  72.